package kr.blogspot.stiner01.moduletutorial;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;

public class SingleTouchTest extends Activity implements OnTouchListener
{
    private StringBuilder _builder = new StringBuilder();
    private TextView _textView = null;
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        _textView = new TextView(this);
        _textView.setText("Touch and drag (one finger only)!");
        _textView.setOnTouchListener(this);
        
        setContentView(_textView);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        _builder.setLength(0);
        
        switch (event.getAction())
        {
        case MotionEvent.ACTION_DOWN:
            _builder.append("down, ");
            break;
            
        case MotionEvent.ACTION_MOVE:
            _builder.append("move, ");
            break;
            
        case MotionEvent.ACTION_CANCEL:
            _builder.append("cancel, ");
            break;
            
        case MotionEvent.ACTION_UP:
            _builder.append("up, ");
            break;
        }
        
        _builder.append(event.getX());
        _builder.append(", ");
        _builder.append(event.getY());
        
        String text = _builder.toString();
        Log.d("TouchTest", text);
        _textView.setText(text);
        
        return true;
    }
}
